<?php

function getThumbnail($image_file, $model, $key, $scale = true, $inflate = true, $quality = 75)
{
	$d = sfConfig::get('app_thumbnails_'.$model);
	$ddir = $d[$key]['w'].'x'.$d[$key]['h'];
	$thumbnail_dir = sfConfig::get('sf_upload_dir'). '/' . $model . '/' . $ddir .'/';
	$thumbnail_file = $thumbnail_dir . $image_file;
	if (!file_exists($thumbnail_file))
	{
		if (!is_dir($thumbnail_dir))
		{
			mkdir($thumbnail_dir, 0777);
		}
		if (!file_exists(sfConfig::get('sf_upload_dir'). '/' . $model . '/' .$image_file))
		{
			$image_file = 'default.jpg';
		}
		$thumbnail = new sfThumbnail($d[$key]['w'], $d[$key]['h'], $scale, $inflate, $quality);
		$thumbnail->loadFile(sfConfig::get('sf_upload_dir'). '/' . $model . '/' .$image_file);
		$thumbnail->save($thumbnail_file);
	}
	return '/uploads/' . $model . '/' . $ddir .'/'. $image_file;
}

?>
